import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    redirect: {name:'logins'}
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/AboutView.vue')
  },
  {
    path: '/login',
    name:'login',
    component: () => import('../views/login.vue')
  },
  {
    path: '/logins',
    name:'logins',
    component: () => import('../views/login/logins.vue')
  },
  {
    path: '/index',
    name:'index',
    component: () => import('../views/index.vue')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})


function dynami(){
  let token =localStorage.getItem('token')
  let list = JSON.parse(localStorage.getItem('menuList'))
  if(token && list){
      let newlist =fu(list)
      newlist.forEach((item)=>{
        router.addRoute('Test',item)
      })
  }
}
dynami()
export default router
